<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>博客管理</title>
<link rel="stylesheet" href="/networkforum/css/user_info.css" />

<link rel="stylesheet" href="/networkforum/css/user_control_article.css" />
<script type="text/javascript">
var groupOption = {
	'groupName':{
		'param':{
			'id':'articleLi','onclick':loadArticles
		},
		'bind':{
			'groupId':'groupId'
		},
	}
};
var group = {
	'targetId':"groups",
	'data':null
};
window.onload = function(){
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/article/article_group.do",function(d){
		//var data = eval("("+d+")");
		var data = toJson(d);
		group['data'] = data;
	});
	//page.combo("articleInner",param,groupOption);

	myajax = null;
}
function showGroups(){
	page.combo("articleInner",group,groupOption);
}
function loadArticles(event){
	event = event||window.event;
	var target = event.target||event.srcElement;
	var groupId = target.groupId;

	document.getElementById("groups").value = target.innerHTML;
	document.getElementById("articleInner").style.display = 'none';


	var ulGroup = document.getElementById("ulGroup");
	var first = ulGroup.children[0];
	var header = ulGroup.children[1];
	ulGroup.innerHTML = "";
	ulGroup.appendChild(first);
	ulGroup.appendChild(header);

	var repyInner = document.getElementById("replyInner");
	var first = replyInner.children[0];
	var header = replyInner.children[1];
	replyInner.innerHTML = "";
	replyInner.appendChild(first);
	replyInner.appendChild(header);
	
	//登录页面后通过myajax获取进一步的信息
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/article_group/article_list.do?groupId="+groupId,function(d){
		//var data = eval("("+d+")");
		var data = toJson(d);
		articleLi['data'] = data;
		page.view("ulGroup",data.slice(0,10),articleOption);
		paging.page({
			size:10,
			total:Math.ceil(data.length/10),
			data:data,
			ajaxLoad:false,
			previou:document.getElementById("previouPage1"),
			next:document.getElementById("nextPage1"),
			current:document.getElementById("currentPage1"),
			max:document.getElementById("totalPage1"),
			callBack:function(d){
				var ulGroup = document.getElementById("ulGroup");
				var first = ulGroup.children[0];
				var module = ulGroup.children[1];
				ulGroup.innerHTML = "";
				ulGroup.appendChild(first);
				ulGroup.appendChild(module);
				//page.view("replyInner",d,replyOption);
				page.view("ulGroup",d,articleOption);
				moule = null;
				frist= null;
				friendInner = null;
			},
		});
	});
	myajax = null;
}
/*var articleOption = {
	'articleName':{
		'param':{
			'id':'articleLi','onclick':getArticleReply
		},
		'bind':{
			'articleId':'articleId','isPublic':"isPublic",'isReply':"isReply"
		},
	}
};*/
var articleOption = {
	'articleName':{
		'param':{
			'id':'articleTitle','onclick':getArticleReply
		},
		'bind':{
			'articleId':'articleId','isPublic':"isPublic",'isReply':"isReply"
		},
	},
	'isPublic':{
		'param':{
			'id':'articlePublic','onclick':getArticleReply
		},
	},
	'isReply':{
		'param':{
			'id':'articleReply','onclick':getArticleReply
		},
	}
};
var articleLi = {
		'targetId':"article",
		'data':null
	};
/**function showArticles(){
	//page.combo("articleInner",articleLi,articleOption);
	page.view("ulGroup",articleLi['data'],articleOption);
}*/
function getArticleReply(event){
	event = event||window.event;
	var target = event.target||event.srcElement;
	var articleId = target.articleId;

	levelHandle(target.isPublic,target.isReply);

	var article = document.getElementById("article");
	article.value = articleId;
	//document.getElementById("article").value = target.innerHTML;
	//document.getElementById("article").articleId = articleId;
	
	document.getElementById("articleInner").style.display = 'none';
	
	//登录页面后通过myajax获取进一步的信息
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/article/reply_list.do?articleId="+articleId,function(d){
		var repyInner = document.getElementById("replyInner");
		var first = replyInner.children[0];
		var header = replyInner.children[1];
		replyInner.innerHTML = "";
		replyInner.appendChild(first);
		replyInner.appendChild(header);
		//var data = eval("("+d+")");
		var data = toJson(d);
		
		page.view("replyInner",data.slice(0,10),replyOption);

		paging.page({
			size:10,
			total:Math.ceil(data.length/10),
			data:data,
			ajaxLoad:false,
			previou:document.getElementById("previouPage2"),
			next:document.getElementById("nextPage2"),
			current:document.getElementById("currentPage2"),
			max:document.getElementById("totalPage2"),
			callBack:function(d){
				var replyInner = document.getElementById("replyInner");
				var first = replyInner.children[0];
				var module = replyInner.children[1];
				replyInner.innerHTML = "";
				replyInner.appendChild(first);
				replyInner.appendChild(module);
				page.view("replyInner",d,replyOption);
				moule = null;
				frist= null;
				friendInner = null;
			},
		});
	});
	myajax = null;
}
var replyOption={
	'userName':{
		'param':{'id':"userName"},
		'bind':{'replyId':"replyId"}
	},
	'replyContent':{
		'param':{'id':"replyContent"},
	},
	'replyDate':{
		'param':{'id':"replyTime"},
	}
}
function levelHandle(isPublic,isReply){
	if(isPublic=="是"){
		document.getElementById("isPublic").checked = "checked";
	}
	if(isReply=="是"){
		document.getElementById("isReply").checked = "checked";
	}
}
function deleteReply(obj){
	var ul = document.getElementById("replyInner");
	ul.removeChild(obj);
	var replyId = obj.children[0].replyId;
	
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/reply/delete_reply.do?moduleName=article&replyId="+replyId,function(d){
	});
	myajax = null;
}
function updateLevel(){
	var isPublic = document.getElementById("isPublic").checked;
	var isReply = document.getElementById("isReply").checked;
	var articleId = document.getElementById("article").value;
	if(!articleId){
		alert("请先选择一篇文章");
		return;
	}
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/article/update_leavel.do?articleId="+articleId+"&isPublic="+isPublic+"&isReply="+isReply,function(d){
		//var data = eval("("+d+")");
		var data = toJson(d);
		alert(data.result);
		//location.reload();
	});
	myajax = null;
}
</script>
</head>

<body>
	<h2 class="header">博客管理</h2>
	<div class="articleGroup">
		<span>组名：</span><input id="groups" type="text" value="点击选择" onclick="showGroups()"/>	
		<!-- -<span>文章：</span><input id="article" type="text" value="点击选择" onclick="showArticles()"/>
		 -->
		<ul id="articleInner" style="display:none;">
			<li class=""><span id="articleLi"/></li>
		</ul>
	</div>
	<div class = "groupInner">
		<h2>文章</h2>
		<ul class="ulGroup" id="ulGroup">
			<li style="display: none;">
				<span id="articleTitle"></span>
				<span id="articlePublic"></span>
				<span id="articleReply"></span>
				<span id="handle" onclick="deleteInfo(event);">删除</span>
			</li>
			<li id="groupHeader">
				<span id="articleTitle">标题</span>
				<span id="articlePublic">公开</span>
				<span id="articleReply">评论</span>
			</li>
		</ul>
		<div class="paging" id="paging">
	   		<div class="clear"></div>
	   		<span id="previouPage1" style="cursor: pointer;">上一页</span>
	   		<input id="currentPage1" type="text" value = "1"/>	
	   		<span id="nextPage1" style="cursor: pointer;">下一页</span>
	   		<span id="totalPage1">共 1 页</span>
	   	</div>
	</div>
	<div class="controlInner">
		<input type="text" style="display: none" id="article"/>
		<h2>评论</h2>
		<ul class="replyInner" id="replyInner">
			<li style="display: none;">
				<span id="userName"></span>
				<span id="replyContent"></span>
				<span id="replyTime"></span>
				<span id="handle" onclick="deleteReply(this.parentElement)">删除</span>
			</li>		
			<li id="replyHeader">
				<span id="userName">用户名</span>
				<span id="replyContent">内容</span>
				<span id="replyTime">评论时间</span>
				<span id="handle">操作</span>
			</li>
		</ul>
		<div class="paging" id="paging">
	   		<div class="clear"></div>
	   		<span id="previouPage2" style="cursor: pointer;">上一页</span>
	   		<input id="currentPage2" type="text" value = "1"/>	
	   		<span id="nextPage2" style="cursor: pointer;">下一页</span>
	   		<span id="totalPage2">共 1 页</span>
	   	</div>
	</div>
	<h2>权限设置</h2>
	<div class="param">
		<div>
			<span>是否公开</span><input id="isPublic" type="checkbox" />
		</div>
		<div>
			<span>是否可评论</span><input id="isReply" type="checkbox" />
		</div>
		<span id="save" onclick="updateLevel()">保存</span>
	</div>
</body>
<script src="/networkforum/js/view.js" type="text/javascript"></script>
<script src="/networkforum/js/combo.js" type="text/javascript"></script>
<script src="/networkforum/js/myajax.js" type="text/javascript"></script>
<script src="/networkforum/js/pageing.js" type="text/javascript"></script>
</html>
